<%@ Page Language="VB" MasterPageFile="~/site.master" AutoEventWireup="false" codefile="EditSquad.aspx.vb" Inherits="EditSquad" %>
<%@ Register TagPrefix="wu" TagName="PictureUpload" Src="../PictureUpload.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="server">

    <asp:sqldatasource id="PlayersDataSource" runat="server"
        selectcommand="SELECT [PlayerID], [FirstName], [LastName], [Position], [PictureURL], [DateJoined], [DateLeft] FROM [Players]"
        connectionstring="<%$ ConnectionStrings:WroxUnited %>">
    </asp:sqldatasource>
    
    <asp:gridview
        id="GridView1" runat="server" datakeynames="PlayerID" datasourceid="PlayersDataSource"
        emptydatatext="There are no data records to display." autogeneratecolumns="False"
        allowpaging="True" PageSize="8" allowsorting="True" CssClass="grid">
        <SelectedRowStyle CssClass="rowSelected" />        
        <Columns>
            <asp:BoundField ReadOnly="True" HeaderText="PlayerID" DataField="PlayerID" SortExpression="PlayerID" Visible="False"></asp:BoundField>
            <asp:BoundField HeaderText="First Name" DataField="FirstName" SortExpression="FirstName"></asp:BoundField>
            <asp:BoundField HeaderText="Last Name" DataField="LastName" SortExpression="LastName">
            </asp:BoundField>
                <asp:TemplateField SortExpression="Position" HeaderText="Position">
                <EditItemTemplate>
                    <asp:DropDownList id="DropDownList1" runat="server" SelectedValue='<%# Bind("Position") %>'>
                        <asp:ListItem Selected="True">Goalkeeper</asp:ListItem>
                        <asp:ListItem>Left Back</asp:ListItem>
                        <asp:ListItem>Right Back</asp:ListItem>
                        <asp:ListItem>Central Defender</asp:ListItem>
                        <asp:ListItem>Midfield</asp:ListItem>
                        <asp:ListItem>Left Wing</asp:ListItem>
                        <asp:ListItem>Right Wing</asp:ListItem>
                        <asp:ListItem>Striker</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("Position") %>' id="Label1"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField HeaderText="PictureURL" DataField="PictureURL" SortExpression="PictureURL"></asp:BoundField>
            <asp:BoundField HeaderText="Date Joined" DataField="DateJoined" SortExpression="DateJoined" DataFormatString="{0:dd-MMM-yy}"></asp:BoundField>
            <asp:BoundField HeaderText="Date Left" DataField="DateLeft" SortExpression="DateLeft" DataFormatString="{0:dd-MMM-yy}"></asp:BoundField>
            <asp:CommandField ShowSelectButton="True" SelectText="More details"></asp:CommandField>
        </Columns>
    </asp:gridview>
    
    <asp:sqldatasource id="DetailsDataSource" runat="server"
        updatecommand="UPDATE [Players] SET [FirstName] = @FirstName, [LastName] = @LastName, [Position] = @Position, [PictureURL] = @PictureURL, [DateJoined] = @DateJoined, [DateLeft] = @DateLeft WHERE [PlayerID] = @PlayerID"
        insertcommand="INSERT INTO [Players] ([FirstName], [LastName], [Position], [PictureURL], [DateJoined], [DateLeft]) VALUES (@FirstName, @LastName, @Position, @PictureURL, @DateJoined, @DateLeft)"
        deletecommand="DELETE FROM [Players] WHERE [PlayerID] = PlayerID"
        selectcommand="SELECT [PlayerID], [FirstName], [LastName], [Position], [PictureURL], [DateJoined], [DateLeft] FROM [Players] WHERE ([PlayerID] = @PlayerID)"
        connectionstring="<%$ ConnectionStrings:WroxUnited %>" OnUpdated="DetailsDataSource_Updated" OnInserted="DetailsDataSource_Inserted">
        <DeleteParameters>
            <asp:Parameter Type="String" Name="PlayerID"></asp:Parameter>
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Type="String" Name="FirstName"></asp:Parameter>
            <asp:Parameter Type="String" Name="LastName"></asp:Parameter>
            <asp:Parameter Type="String" Name="Position"></asp:Parameter>
            <asp:Parameter Type="String" Name="PictureURL"></asp:Parameter>
            <asp:Parameter Type="DateTime" Name="DateJoined"></asp:Parameter>
            <asp:Parameter Type="DateTime" Name="DateLeft"></asp:Parameter>
            <asp:Parameter Type="String" Name="PlayerID"></asp:Parameter>
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter Name="PlayerID" Type="String" ControlID="GridView1" PropertyName="SelectedValue"></asp:ControlParameter>
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter Type="String" Name="FirstName"></asp:Parameter>
            <asp:Parameter Type="String" Name="LastName"></asp:Parameter>
            <asp:Parameter Type="String" Name="Position"></asp:Parameter>
            <asp:Parameter Type="String" Name="PictureURL"></asp:Parameter>
            <asp:Parameter Type="DateTime" Name="DateJoined"></asp:Parameter>
            <asp:Parameter Type="DateTime" Name="DateLeft"></asp:Parameter>
        </InsertParameters>
    </asp:sqldatasource>
    
    <asp:detailsview id="DetailsView1" runat="server" datakeynames="PlayerID" datasourceid="DetailsDataSource"
        autogeneraterows="False" CssClass="details">
        <HeaderTemplate>Edit Player</HeaderTemplate>
        <HeaderStyle CssClass="detailsHeader" />
        <FieldHeaderStyle CssClass="detailsFieldHeader" />
        <Fields>
            <asp:BoundField ReadOnly="True" HeaderText="PlayerID" InsertVisible="False" DataField="PlayerID" SortExpression="PlayerID" Visible="False"></asp:BoundField>
            <asp:BoundField HeaderText="First Name:" DataField="FirstName" SortExpression="FirstName"></asp:BoundField>
            <asp:BoundField HeaderText="Last Name:" DataField="LastName" SortExpression="LastName"></asp:BoundField>
            <asp:TemplateField SortExpression="Position" HeaderText="Position:">
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("Position") %>' id="Label1"></asp:Label>
                </ItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList id="DropDownList1" runat="server" SelectedValue='<%# Bind("Position") %>'><asp:ListItem Selected="True">Goalkeeper</asp:ListItem>
                        <asp:ListItem>Left Back</asp:ListItem>
                        <asp:ListItem>Right Back</asp:ListItem>
                        <asp:ListItem>Central Defender</asp:ListItem>
                        <asp:ListItem>Midfield</asp:ListItem>
                        <asp:ListItem>Left Wing</asp:ListItem>
                        <asp:ListItem>Right Wing</asp:ListItem>
                        <asp:ListItem>Striker</asp:ListItem>
                    </asp:DropDownList>
                </InsertItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList id="DropDownList1" runat="server" SelectedValue='<%# Bind("Position") %>'><asp:ListItem Selected="True">Goalkeeper</asp:ListItem>
                        <asp:ListItem>Left Back</asp:ListItem>
                        <asp:ListItem>Right Back</asp:ListItem>
                        <asp:ListItem>Central Defender</asp:ListItem>
                        <asp:ListItem>Midfield</asp:ListItem>
                        <asp:ListItem>Left Wing</asp:ListItem>
                        <asp:ListItem>Right Wing</asp:ListItem>
                        <asp:ListItem>Striker</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField SortExpression="PictureURL" HeaderText="Picture Name:"><EditItemTemplate>
                    <asp:TextBox runat="server" Text='<%# Bind("PictureURL") %>' id="TextBox1" Columns="30"></asp:TextBox><br />
                    <wu:PictureUpload id="PictureUpload1" runat="server" UploadImageType="Player"
                        OnFileUploaded="FileUploaded"></wu:PictureUpload>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("PictureURL") %>' id="Label2"></asp:Label>
                </ItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox runat="server" Text='<%# Bind("PictureURL") %>' id="TextBox1" Columns="30"></asp:TextBox><br />
                    <wu:PictureUpload id="PictureUpload2" runat="server" UploadImageType="Player"
                        OnFileUploaded="FileUploaded"></wu:PictureUpload>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:BoundField HeaderText="Date Joined:" DataField="DateJoined" SortExpression="DateJoined" DataFormatString="{0:dd-MMM-yy}"></asp:BoundField>
            <asp:BoundField HeaderText="Date Left:" DataField="DateLeft" SortExpression="DateLeft" DataFormatString="{0:dd-MMM-yy}"></asp:BoundField>
            <asp:CommandField ShowInsertButton="True" ShowEditButton="True" ShowDeleteButton="True"></asp:CommandField>
        </Fields>
    </asp:detailsview>
    <asp:label id="Status" runat="server" /></asp:Content>
